home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-20 / rs0422.zip / ROSEZSW / CALSETUP.C next >
C/C++ Source or Header  |  1990-09-20  |  8KB  |  220 lines

  1. /*
  2.  * Copyright 1988 by the Radio Amateur Telecommunications Society
  3.  * and Thomas A. Moulton, W2VY
  4.  *
  5.  * This software may only be modified, copied, distributed or
  6.  * executed for non-profit purposes by individuals operating
  7.  * systems in the Amateur Radio Service.  Credit to the
  8.  * author(s) and to the Radio Amateur Telecommunications Society
  9.  * must be made in modules where RATS provided software is used,
  10.  * and in any announcements and documentation.  
  11.  *
  12.  * As a non-profit, research and development organization,  the
  13.  * Radio Amateur Telecommunications Society distributes software
  14.  * in both executable and source forms.  This policy is in place
  15.  * to encourage the development and distribution of OSI-based,
  16.  * networking tools.  In order to protect the interests of the
  17.  * Society and the authors, we have placed some conditions
  18.  * of use on the software.  Other groups are encouraged
  19.  * to place the same or similar guidelines on
  20.  * software they produce.
  21.  *
  22.  * The Radio Amateur Telecommunications Society reserves the right
  23.  * to specify and alter the terms under which software provided by
  24.  * the Society may be used.  This policy is consistent with the 
  25.  * objective of uniform and consistent "Open Systems Interconnections."
  26.  * 
  27.  * All acceptable Amateur Radio related uses of this software
  28.  * will be outlined in the "ROSE Implementer's Guide".  Individuals
  29.  * or organizations wishing to add to, or modify the provisions of
  30.  * the guide to accommodate local or evolutionary requirements
  31.  * should document the proposed change(s) and forward them to the
  32.  * Society.  If accepted, written notification will be provided by
  33.  * the Society to the submitting organization or individual(s).
  34.  * The Society will then issue a "ROSE Implementer's Guide Change
  35.  * Notice".  Periodically, the Society will re-issue the "ROSE 
  36.  * Implementer's Guide" and incorporate the text of the change 
  37.  * notices.  This procedure has been put in to place to ensure
  38.  * compatibility between systems and to ensure their "Openness"
  39.  * and interoperability.
  40.  *
  41.  * No part of this software may be used in other packages 
  42.  * without prior authorization from the author or the Society.  
  43.  * Software incorporating this module, all or in part, must be 
  44.  * provided to the Society prior to distribution or use by
  45.  * anyone not directly involved in testing of the revised  
  46.  * environment.  Current releases of the combined software must
  47.  * be provided to the Society in both source and executable
  48.  * forms.  Adequate documention to produce an executable module 
  49.  * from the provided source must also be included.
  50.  *
  51.  * Non-Amateur Radio non-profit uses may be authorized on a case
  52.  * by case basis.  Inquiries for such use may be made in writing
  53.  * to the Society. Non-commercial uses consistent with the
  54.  * general principles of Open Systems Interconnection Reference
  55.  * Model will be generally considered with favor.
  56.  *
  57.  * Commercial licensing of the software is also available based
  58.  * on normal commercial terms.  Licensing inquiries should be
  59.  * directed to the Society.  Commercial licensing of the standard
  60.  * software will be done in situations which materially benefit
  61.  * the Amateur Radio Packet Network.  Additional licensing is
  62.  * reserved by the individual authors.
  63.  * 
  64.  * The Radio Amateur Telecommunications Society provides this software
  65.  * on an "as is" basis.  The Society assumes no liability for
  66.  * loss incurred through the use of this software.  Amateur Radio
  67.  * use of this software implies non-commercial and voluntary 
  68.  * development, deployment and use of this software in a "Amateur",
  69.  * non-commercial service.  Commercial users are encouraged to
  70.  * inspect their copies of the source code.  Source code modification
  71.  * licenses are available if a combined Object and Source Code
  72.  * license was not originally established.
  73.  * 
  74.  * The Society may be contacted by writing or calling at:
  75.  * 
  76.  * The Radio Amateur Telecommunications Society 
  77.  * 206 North Vivyen Street.
  78.  * Bergenfield, New Jersey 07621
  79.  *
  80.  * Telephone: 201-387-8896
  81.  *
  82.  */
  83. /* This file has the generic call setup routines */
  84.  
  85. #include "data.h"
  86. #include "buffer.h"
  87. #include "ax25.h"
  88. #include "ax25l2.h"
  89. #include "l3struc.h"
  90. #include "x25cause.h"
  91. #include "l3calls.h"
  92. #include "upfcn.h"
  93.  
  94. /* Call Request assumes to have a set of linked peers and wants to
  95.     be passed the one with out a parent, and we will try to
  96.     find a link to adopt it (sorry couldn't resist) */
  97.  
  98. extern int userport;
  99. extern struct ax25_addr *L2_source, L2_destin[6];
  100. extern unsigned char node_addr[16];
  101. extern int maxfcn;
  102. extern struct upfcn *spcfcn[];
  103.  
  104. int check_x121(), callcmp(), find_call(), find_route(), find_path();
  105. struct axcb *linked_to(), *USER_CONN(), *NET_CONN();
  106.  
  107. call_request(vc)
  108. register struct VCS *vc;
  109. {
  110.     static unsigned int cause, uport;
  111.     static int i;
  112.     static unsigned char *altlist;
  113.     static struct VCS *vcx;
  114.     int internal_fcn();
  115.  
  116.     cause=Congestion+120; /* Default to no memory */
  117.     kill(vc->timer);    /* In case we were queued */
  118.     vc->lcn = 255;        /* This call is Not active */
  119.     get_nsap(vc,&L2_destin[0]);
  120.     if ((check_x121(node_addr,vc->addr) != -1)) /* This node, Local call */ {
  121.         vc->alt = 254;    /* Local Outbound Call */
  122.         if (internal_fcn(&L2_destin[0],vc)) /* The buck stops here! */ {
  123.             vc->P=P2;
  124.             vc->lcn = 0;    /* Call is no longer pending */
  125.             set_p(vc,P4,0);
  126.             return;
  127.         }
  128.         i=find_call(&L2_destin[0]);
  129.         uport = userport;
  130.         if ((i >= 0) && (L3_MAXVC[i] == 0)) {
  131.             uport = L3PORT[i];
  132.             if (!vc->digi.call[0]) callcpy(&vc->digi, &L3DIGI[i]);
  133.             i= -1;
  134.         }
  135.         if (i<0) /* Not a Level 3 user */ {
  136.             vc_l2_pars(vc);
  137.  
  138.             vcx=vc->peer;
  139.             l2_adr(vcx->addr,&L2_destin[2], &L2_destin[3]);
  140.             get_nsap(vcx,&L2_source);
  141.             if (linked_to(&L2_destin[0],&L2_source,&i)) {
  142.                 cause = Number_Busy+72;    /* Call Collision */
  143.                 goto error;
  144.             }
  145.  
  146.             vc->lcn=0; /* Level 2 User */
  147.             vc->P=P2;
  148.             if (! (vc->parent=USER_CONN(uport, vc))) goto error;
  149.             insert_lcn(vc);     /* Queue call, no alternatives */
  150.             return;
  151.         }
  152.         else /* Local Level 3 Call */ {
  153.             if (i<16) /* A network node, illegal */ {
  154.                 cause = Access_Barred+245;
  155.                 goto error;
  156.             }
  157.             vc->rand=0;    /* Leaving the network */
  158.             vc->addr[0]=vc->peer->addr[0]=0;
  159.             if (! linked_to(&L2_destin[0],&L3CALL[0],&vc->parent)) /* New Link */ {
  160.                 if ((vc->parent=NET_CONN(i)) == NULL) goto error;
  161.             }
  162.             if (vc->parent->R == R1) set_p(vc,P2,0);
  163.             else /* Link is not ready, queue call in llcn */ {
  164.             /*    vc->lcn=255; /* Level 3 call pending */
  165.                 insert_lcn(vc); /* append call */
  166.             }
  167.             return;
  168.         }
  169.     } else /* Remote Level 3 call do routing */ {
  170.         i = find_route(&altlist, vc->addr);
  171.  
  172.         if (i == -1) /* Modified address, re-route */ {
  173.             vc->alt = 255;    /* Clear, Address changed */
  174.             queue(&vc->timer, call_request, 0, vc);
  175.             return;
  176.         } else
  177.         if (i == 0) /* No Path */ {
  178.             cause=Not_Obtainable;
  179.             goto error;
  180.         }
  181.         i = (altlist[0]>>4) & 0x0f;
  182.         if (!i) /* Internal ERROR */ {
  183.             cause=Not_Obtainable+119;
  184.             goto error;
  185.         }
  186.     /*    vc->lcn = 255; */
  187.         vc->tx_queue = (struct datastr *)altlist;
  188.         if ((find_path(vc) == TRUE)) return;
  189.         if (vc->alt == 255) cause=Out_of_Order;    /* No good routes */
  190.         /* else No memory */
  191.     }
  192. error: /* Fall Through, error */
  193.     vc->peer->peer = NULL;
  194.     vc->parent = NULL;
  195.     set_p(vc->peer,P6, cause);
  196.     free(vc);
  197. }
  198.  
  199. int
  200. internal_fcn(stn,vc)
  201. struct ax25_addr *stn;
  202. struct VCS *vc;
  203. {
  204.     register struct upfcn *spc;
  205.     static int i;
  206.  
  207.     for (i=0;i<maxfcn;i++) /* Check for all internal functions */ {
  208.         spc = spcfcn[i];
  209.         if (callcmp(stn, &spc->dnam)) {
  210.             vc->RESET = spc->reset;
  211.             vc->CLEAR = spc->clear;
  212.             vc->SEND = spc->send;
  213.             vc->RECV = spc->recv;
  214.             vc->CONNECTED = spc->conn;
  215.             return 1;
  216.         }
  217.     }
  218.     return 0;
  219. }
  220.